package xml;

import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class ReadXML {

	static void readTheFile(String fileName) throws ParserConfigurationException, SAXException, IOException {
		File xmlFile = new File(fileName);
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setIgnoringElementContentWhitespace(true);		
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse(xmlFile);		
		Node root = doc.getFirstChild();
		System.out.println(root);		
		NodeList nodes = root.getChildNodes();
		Node stands = null;
		
		for (int index =0; index < nodes.getLength(); index++) {
			Node node = nodes.item(index);
			System.out.println(nodes);
			if(node.getNodeName().equals("stands")) {
				stands = node;
				break;
			}
		}
		
		
		Node whereIslelqSiikaPoDqvolite = stands.getFirstChild();
		while (!whereIslelqSiikaPoDqvolite.getNodeName().equals("owner")){
			whereIslelqSiikaPoDqvolite = whereIslelqSiikaPoDqvolite.getNextSibling();
		}System.out.println(whereIslelqSiikaPoDqvolite.getTextContent());
		
		Node products = root.getFirstChild();
		while(!products.getNodeName().equals("products")) {
			products = products.getNextSibling();
			
		}
		
	}
	
	public static void main(String[] args) {
		try {
			readTheFile("Market.xml");
		} catch (ParserConfigurationException e) {
			
			e.printStackTrace();
		} catch (SAXException e) {
			
			e.printStackTrace();
		} catch (IOException e) {
			
			e.printStackTrace();
		}

	}

}
